package com.jake.data_structure_learning.search;

/**
 * copyright (C), 2021, 武汉德辞信息技术有限公司
 *
 * @author WangXiang
 * @version 1.0.0
 * @create 2021/6/24 11:25
 * @description <author>                <time>                  <version>
 * WangXiang               2021/6/24 11:25            1.0.0
 */
public class Search {

    public static int binarySearch(int[] nums, int value) {
        int start = 0;
        int end = nums.length - 1;
        while (start < end) {
            int mid = (start + end) / 2;
            if (nums[mid] < value) {
                start = mid + 1;
            } else if (nums[mid] == value) {
                return mid;
            } else {
                end = mid - 1;
            }
        }
        return -1;
    }
}
